<%@ include file="header.jsp" %>
<%
	String method = "post";
	if (request.getParameter("method") != null) {
		method = request.getParameter("method");
	}
%>
<%@page import="org.jcommon.xml.XMLSerialization"%>
<b style="font-size: 18pt;">Test Service: <%=request.getParameter("service")%></b><br/>
<%
	if (method.equals("post")) {
%>
	<b id="Post">Post</b>
<%
	} else {
%>
	<a id="Post" href="test.jsp?method=post&service=<%=request.getParameter("service")%>">Post</a>
<%
	}
%>
|
<%
	if (method.equals("get")) {
%>
	<b id="Get">Get</b>
<%
	} else {
%>
	<a id="Get" href="test.jsp?method=get&service=<%=request.getParameter("service")%>">Get</a>
<%
	}
%>
|
<a id="WebServiceRequester" href="wsr/wsr.jsp?service=<%=request.getParameter("service")%>">Web Service Requester</a>
<br/><br/>
<table cellpadding="4" cellspacing="0" style="border: 1px solid #000000;">
	<tr bgcolor="<%= CSSDefaults.BG_COLOR %>">
		<td class="table" id="MethodName"><a href="#" class="menu">Method Name</a></td>
		<td class="table" id="Return"><a href="#" class="menu">Return</a></td>
		<td class="table" id="Parameters"><a href="#" class="menu">Parameters</a></td>
		<td class="table" id="Actions"><a href="#" class="menu">Actions</a></td>
	</tr>
<%
	com.googlecode.jwsm.Service service = com.googlecode.jwsm.ServiceManager.getInstance().getService(request.getParameter("service"));
	if (service != null) {
		java.lang.reflect.Method[] methods = service.getMethods();
		for (int i = 0; i < methods.length; i++) {
	if (methods[i].getName().equals("getClass")) continue;
	String returnString = methods[i].getReturnType().getName();
	if (methods[i].getReturnType().isArray()) {
		returnString = returnString.substring(2, returnString.length() - 1) + "[]";
	}
%>
	<tr valign="top">
		<td class="log"><%= methods[i].getName() %></td>
		<td class="log"><%= returnString %></td>
		<td class="log"><form id="form<%= i %>" method="<%= method %>" action="ServiceRequest/<%= service.getName() %>/<%= methods[i].getName() %>">
			<%
				Class[] params = methods[i].getParameterTypes();
				for (int j = 0; j < params.length; j++) {
					String paramString = params[j].getName();
					if (params[j].isArray()) {
						paramString = paramString.substring(2, paramString.length() - 1) + "[]";
					}
					String sample = XMLSerialization.generateSample(params[j], service.getClassLoader());
					if (sample == null) sample = "";
			%>
					<textarea id="testParam<%= i %>:<%= j %>" style="display: none;"><%= sample %></textarea>
					<table border="0" cellpadding="4" cellspacing="0"><tr valign="top"><td style="font-size: small;"><%= paramString %></td><td style="font-size: small;"><span id="span<%= i %>:<%= j %>"><input type="text" id="param<%= i %>:<%= j %>" name="param<%= j %>"/><input type="button" value="Expand" onclick="expand(<%= i %>, <%= j %>);"/></span></td></tr></table>
			<%
				}
				if (params.length == 0) {
			%>
					<i>No parameters</i>
			<%
				}
			%>
		</form></td>
		<td class="log">
			<select onchange="executeAction('Eval', this);">
				<option>-- Execute --</option>
				<option value="document.getElementById('form<%= i %>').submit();">Invoke Service</option>
				<option value="document.location = 'ServiceRequest/<%= service.getName() %>/<%= methods[i].getName() %>?wsdl';">Generate WSDL</option>
				<option value="document.getElementById('form<%= i %>').action = 'GenerateJUnit/<%= service.getName() %>/<%= methods[i].getName() %>'; document.getElementById('form<%= i %>').submit();">Generate JUnit Test</option>
				<% if ((methods[i].getParameterTypes().length > 0) && (methods[i].getParameterTypes()[0] != java.io.InputStream.class)) { %><option value="populateTestParameters(<%= i %>, <%= methods[i].getParameterTypes().length %>);">Populate Test Parameters</option><% } %>
			</select>
			<!--<input type="button" value="Execute" onclick="document.getElementById('form<%= i %>').submit();"/>
			<input type="button" value="WSDL" onclick="document.location = 'ServiceRequest/<%= service.getName() %>/<%= methods[i].getName() %>?wsdl';"/>
			<input type="button" value="JUnit" onclick="document.getElementById('form<%= i %>').action = 'GenerateJUnit/<%= service.getName() %>/<%= methods[i].getName() %>'; document.getElementById('form<%= i %>').submit();"/>-->
		</td>
	</tr>
<%
		}
	} else {
%>
	<tr>
		<td class="table" colspan="5"><i>Service not found: <%= request.getParameter("service") %></i></td>
	</tr>
<%
	}
%>
</table>
<%@ include file="footer.jsp" %>